﻿using System.Linq;
using RealEstate.Models;
using System.Collections.Generic;
namespace RealEstate
{
    public partial class PropertyTypeEntities
    {
        private DataClassesDataContext dataContext = new DataClassesDataContext();

        public void Add(PropertyType item)
        {
            dataContext.PropertyTypes.InsertOnSubmit(item);
            dataContext.SubmitChanges();
        }

        public void Update(PropertyType item)
        {
            var updateItem = (from c in dataContext.PropertyTypes where c.Id == item.Id select c).FirstOrDefault();
            dataContext.SubmitChanges();
        }

        public void Delete(int id)
        {
            var item = (from c in dataContext.PropertyTypes where c.Id == id select c).FirstOrDefault();
            dataContext.PropertyTypes.DeleteOnSubmit(item);
            dataContext.SubmitChanges();
        }

        public PropertyType GetById(int id)
        {
            var item = (from c in dataContext.PropertyTypes where c.Id == id select c).FirstOrDefault();
            return item;
        }

        public List<PropertyType> GetAll()
        {
            return dataContext.PropertyTypes.OrderBy(c => c.Id).ToList();
        }
    }
}